<?php
/**
 * Class Base
 * Desc  基础Model
 * Create on 2021/7/29 12:06
 * Create by wangyafang
 */

namespace app\api\model\xyb;



use think\Model;
use traits\model\SoftDelete;
use think\Request;

class Base extends Model
{
    use SoftDelete;


    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function getList($model,$where = [],$field = '*',$order = 'id desc'){
        $request = Request::instance();
        $param = $request->param();
        $page = isset($param['page']) ? $param['page'] : '';
        $limit = isset($param['limit']) ? $param['limit'] : 10;
        $count = $model->where($where)->count();
        if($page){
            $data = $model->where($where)->page($page,$limit)->order($order)->field($field)->select();
        }else{
            $data = $model->where($where)->order($order)->field($field)->select();
        }
        return ['total'=>$count,'data'=>$data];
    }

    public function getAllList($where = [],$field = '*',$order = 'weigh desc,id desc',$remove = array()){
        $data = $this->where($where)->order($order)->field($field)->select();
        if(!empty($remove)) {
            foreach ($remove as $v) {
                foreach ($data as $kk=>$vv) {
                    unset($data[$kk][$v]);
                }
            }
        }
        return $data;
    }
}